﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Text;
using ReflectionStudio.Core.Events;
using INTEX.DataBase.Tools;
namespace WPFExcelReport
{

    public class JLTWB02KCLCData : BaseFunction
    {
        
        public JLTWB02KCLCData()
            : base()
        {

        }
        public JLTWB02KCLCData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }

        public DataSet GetWB02(DataRow dwABPOS)
        {
            DataSet Result;
            DataSet Return = new DataSet();
            string TableName = "WB02";
            string ART = dwABPOS["ART"].ToString().Trim();
            string LB = dwABPOS["LB"].ToString().Trim();
            string FROMDATE = dwABPOS["FROMDATE"].ToString().Trim();
            string ENDDATE = dwABPOS["ENDDATE"].ToString().Trim();
            try
            {
                
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "select WBBLB,WBBEINDAT,WBBART,WBBFARBE,WBBISTKLG*0.001 AS QTY, "
                    + " (SELECT TRIM(T2.TXTKTEXT) FROM TXTIND T1,TXTKON T2 "
                    + " WHERE T1.TXTIMANDANT = T2.TXTKMANDANT AND T1.TXTIPIND = T2.TXTKPIND "
                    + " AND T1.TXTITXTART = 'WBS' AND TRIM(T1.TXTISIND) = TRIM(A.WBBRWKRS||A.WBBRWLFD||A.WBBPOS) "
                    + " AND T2.TXTKPOS = '10')AS REMARK "
                    + " from wbbst A where wbbmandant = '00' and wbbwakz = 'F' "
                    + " and wbblo = '01' AND WBBLB IN ('KC','LC') AND WBBART LIKE 'J%' "
                    + " AND (WBBEINDAT >= " + FROMDATE + " AND  WBBEINDAT <= " + ENDDATE + ") "
                    + " AND WBBART LIKE '" + ART + "%' AND (WBBLB='" + LB + "' OR  '" + LB + "'='AAA') "
                    + " ORDER BY 1,2 "
                    ;

                Result = Connect2Proxy(orlReadCommand);
                if (Result.Tables.Count > 0)
                {
                    Result.Tables[0].TableName = TableName;
                    /*byte[] b;
                    string value;
                    foreach (DataRow dw in Result.Tables[TableName].Rows)
                    {
                        foreach (DataColumn cm in Result.Tables[TableName].Columns)
                        {
                            string cn = cm.ColumnName;
                            b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw[cn].ToString().Trim());
                            value = Encoding.GetEncoding("gb2312").GetString(b);
                            dw[cn] = value;
                        
                        }
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["STRNAME"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["STRNAME"] = value;
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["ARTNAME"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["ARTNAME"] = value;                       

                        value = dw["TOTRESULT"].ToString().Trim();
                        if (value == "N")
                        {
                            dw["TOTRESULT"] = "不合格";
                        }
                        else if (value == "O")
                        {
                            dw["TOTRESULT"] = "合格";
                        }
                        else 
                        {
                            dw["TOTRESULT"] = "未测试";
                        }
                        
                    }*/
                }
                Return.Merge(Result);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return Return;
        }
        public DataSet BuildJLTWB02KCLCData(DataRow dwUI)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                setResult = GetWB02(dwUI);
                setReturn.Merge(setResult);  
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
    }
}